{{extend 'layout.html'}}

<div id="exploits">
	<div id="vuln_buttons" class="navbar btn-toolbar">
	    <a id="add_exploit" class="btn btn-small"><i class="icon-plus"></i> Add</a>
	    <a id="del_exploit" class="btn btn-small"><i class="icon-remove"></i> Delete</a>
	    <a id="reload_exploits" class="btn btn-small"><i class="icon-refresh"></i> Reload</a>
        <div class="btn-group">
            <a class="btn btn-small dropdown-toggle" data-toggle="dropdown" href="#">
            <i class="icon-asterisk"></i> Import
            <span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
            <li><a href="{{=URL('import_nexpose_xml')}}" target="_blank">Nexpose Exploit List</a></li>
            <li><a href="{{=URL('import_canvas_xml')}}" target="_blank">CANVAS Exploit List</a></li>
            </ul>
        </div>

	</div>

    <table cellpadding="0" cellspacing="0" border="0" class="datatable" id="exploitstable" width="100%">
        <thead>
            <tr>
                <th width="5%"></th>
                <th>Name</th>
                <th>Title</th>
                <th>Description</th>
                <th>Source</th>
                <th>Rank</th>
                <th>Level</th>
                <th>VulnID</th>
                <th>CVE</th>
            </tr>
        </thead>
    </table>
</div>

<div id="add_exploit_modal" class="modal hide fade">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Add Exploit</h3>
  </div>
  <div class="modal-body">
  </div>
  <div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal">Close</a>
    <a href="#" class="btn btn-primary saveBtn">Save</a>
  </div>
</div>

<script type="text/javascript">

var exploitstable;

jQuery(document).ready(function() {
    exploitstable = jQuery('#exploitstable').dataTable( {
        "sAjaxSource": "list.json",
        "sDom": 'T<"clear">lfrtip',
        "oTableTools": {
            "sRowSelect": "multi",
            "sSelectedClass": "row_selected",
            "sSwfPath": "{{=URL(request.application, 'static', 'TableTools/swf/copy_csv_xls.swf')}}",
            "aButtons": [
                "select_all",
                "select_none",
                "copy",
                "csv",
                "print"
            ]
		},
        "aaSorting": [[ 1, "asc" ]],
    } );

    jQuery("#add_exploit").click(function(e) {
        jQuery("#add_exploit_modal").modal({
            "remote": "{{=URL('exploits', 'add.load')}}"
        });
    });

    jQuery("#add_exploit_modal .saveBtn").click(function() {
        ajax_form_submit('#add_exploit_form');
        jQuery('#add_exploit_modal').modal('hide');
    });

    jQuery('#reload_exploits').click( function () {
        exploitstable.fnReloadAjax();
        return false;
    } );

    $("#del_exploit").click(function(e) {
        e.preventDefault();

        bootbox.confirm('These items will be permanently deleted and cannot be recovered. Are you sure?', "Cancel", "Delete Exploit(s)", function(confirmed) {
            if(confirmed) {
                var checks = dt_checkboxer_select_DT_RowIds(exploitstable);
                if (checks == '') { alert('Nothing selected'); return false; }
                var data = "ids=" + checks;
                url = "{{=URL('exploits', 'delete.json', user_signature=True)}}";
                $.web2py.ajax_page( 'POST', url, data, 'undefined' );
            }
        });
    });

} );

</script>
